package com.example.book.sys.dict.controller;

import com.example.book.base.BaseController;
import com.example.book.base.Result;
import com.example.book.domain.sys.SysDict;
import com.example.book.sys.dict.service.SysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author   hcj
 * @date 2018-09-17 21:38:45
*/
@Controller
@RequestMapping(value = "/sys/sysDict")
public class SysDictController extends BaseController{

    @Autowired
    private SysDictService sysDictService;

    @ModelAttribute
    public SysDict get(@RequestParam(required=false) String id) {
        if (StringUtils.isNotBlank(id)){
            SysDict sysDict = new SysDict();
            sysDict.setId(id);
            return sysDictService.get(sysDict);
        }else{
            return new SysDict();
        }
    }

    @RequestMapping(value = "/get")
    @ResponseBody
    public SysDict getById(SysDict sysDict) {
        return sysDict;
    }

    @RequestMapping(value = "/list")
    public String list(SysDict sysDict) {
        return "sys/dict/sys_dict";
    }

    @RequestMapping(value = "/info")
    @ResponseBody
    public List<SysDict> info(SysDict sysDict) {
        return sysDictService.findList(sysDict);
    }


    @RequestMapping(value = "/findPage")
    @ResponseBody
    public PageInfo<SysDict> findPage(SysDict sysDict) {
        return  sysDictService.findPage( sysDict);
    }

    @RequestMapping(value = "/save")
    @ResponseBody
    public Result save(SysDict sysDict) {
        sysDictService.save(sysDict);
        return Result.success("保存成功");
    }

    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@RequestParam("ids") String[] ids){
        sysDictService.delete(ids);
        return Result.success();
    }

}